package com.example.multidatasource.config;

import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.LocalCacheScope;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import javax.sql.DataSource;

@Slf4j
@Configuration
@MapperScan(basePackages = , sqlSessionFactoryRef = )
public class Dd1MybatisConfiguration extends AbstractMybatisConfig {
    public static final String DATA_SOURCE_NAME = "db1DataSource";

    public static final String SQL_SESSION_FACTORY_NAME = "db1SqlSessionFactory";

    public static final String PACKAGE = "";

    public static final String MAPPER_LOCATION = "classpath*:mapper/hpb/*.xml";

    @Resource
    private

    @Bean(name = Dd1MybatisConfiguration.DATA_SOURCE_NAME)
    @ConfigurationProperties(prefix = "spring.datasource.db1")
    public HikariDataSource dataSource() {return getDataSource(DATA_SOURCE_NAME);}

    @Bean(name = Dd1MybatisConfiguration.SQL_SESSION_FACTORY_NAME)
    public SqlSessionFactory sqlSessionFactory(@Qualifier(Dd1MybatisConfiguration.DATA_SOURCE_NAME)DataSource dataSource) {
        try {
            return getSqlSessionFactory(dataSource, properties, MAPPER_LOCATION, LocalCacheScope.STATEMENT);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("{} 初始话异常", DATA_SOURCE_NAME);
        }
    }
}
